package com.zdemo.factors;

import java.math.BigInteger;

public class VolatileFactorHandler {

	private volatile FactorCache cache = new FactorCache(BigInteger.valueOf(0), new BigInteger[]{BigInteger.valueOf(0)});
	
	public BigInteger[] handle(BigInteger number) {
		
		BigInteger i = number;
		BigInteger[] factors = cache.getFactors(i);
		if(factors == null) {
			factors = factor(i);
			cache = new FactorCache(i, factors);
		}
		return factors;
	}
	
	BigInteger[] factor(BigInteger i) {
        return new BigInteger[]{i};
    }
}
